//
//  AppDelegate.m
//  赛拓
//
//  Created by 王磊 on 7/28/16.
//  Copyright © 2016 立金所. All rights reserved.
//

#import "AppDelegate.h"
#import "STTabbarViewController.h"
#import "STLoginViewController.h"
#import "STNavigationController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    [self commitAccountBean];
    
    [self.window makeKeyAndVisible];
    
    [self setProgressHUD];
    
    [self setShareSDK];
    
    return YES;
}

- (void)commitAccountBean {
    
    STAccountBean *accountBean = [STAccountBean new];
    
    [accountBean get];
    
    self.accountBean = accountBean;
}
#pragma mark ---- setAccountBean
- (void)setAccountBean:(STAccountBean *)accountBean {
    _accountBean = accountBean;
    
    
    if (accountBean.token != nil) {
        
        STTabbarViewController *tabbar = [STTabbarViewController instance];
        
        self.window.rootViewController = tabbar;
        
    } else {
        
        STLoginViewController *login = [STLoginViewController instance];
        
        STNavigationController *navi = [[STNavigationController alloc]initWithRootViewController:login];
        
        self.window.rootViewController = navi;
    }
}
#pragma mark ---- setProgressHUD
- (void)setProgressHUD {
    
    [SVProgressHUD setMinimumDismissTimeInterval:1.0];
    
}
- (void)setShareSDK {
    [ShareSDK registerApp:@"1610d1800262e" activePlatforms:@[@(SSDKPlatformTypeSinaWeibo),@(SSDKPlatformSubTypeQZone),@(SSDKPlatformTypeQQ),@(SSDKPlatformSubTypeWechatSession),@(SSDKPlatformSubTypeWechatTimeline),@(SSDKPlatformSubTypeQQFriend)] onImport:^(SSDKPlatformType platformType) {
        switch (platformType)
        {
            case SSDKPlatformTypeWechat:
                [ShareSDKConnector connectWeChat:[WXApi class]];
                break;
            case SSDKPlatformTypeQQ:
                [ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth class]];
                break;
            default:
                break;
        }
    } onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo) {
        
        switch (platformType)
        {
            case SSDKPlatformTypeWechat:
                [appInfo SSDKSetupWeChatByAppId:@"wx7a4027ebd06f4caa"
                                      appSecret:@"f2a2bd3eee8913db658d380cd86d113b"];
                break;
            case SSDKPlatformTypeQQ:
                [appInfo SSDKSetupQQByAppId:@"1105502717"
                                     appKey:@"MGfZ5wMJm7t2CVpU"
                                   authType:SSDKAuthTypeBoth];
                break;
                
            default:
                break;
        }
    }];
}

@end
